package com.stone.back.user.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.ResponseBody;

import com.stone.back.user.dao.IUserDao;
import com.stone.back.user.entity.BfCountry;
import com.stone.back.user.entity.BfUser;
import com.stone.base.entity.Page;

/**
 * 用户管理Service
 * @author Stone P
 *
 */
@Service
public class UserService implements IUserService {
	@Autowired
	private IUserDao userDao;

	/**
	 * 查询登陆信息
	 * @param email			email
	 * @param password		密码
	 * @return				
	 */
	@Override
	public BfUser userLogin(String email, String password) {
		List<BfUser> list = this.userDao.userLogin(email, password);
		BfUser user = null;
		if (0 < list.size()) {
			user = list.get(0);
		}
		return user;
	}
	
	/**
	 * 查询用户分页信息
	 * @param pageNumber						页数
	 * @param userName							用户名
	 * @param email								email
	 * @param sex								性别
	 * @param type(0:普通 1:后台 2：系统管理员)		用户类型
	 * @return
	 */
	@Override
	public Page selectUserPage(int pageNumber, String userName, String email, String sex, String type) {
 		Page page = this.userDao.selectUserPage(pageNumber, userName, email, sex, type);
		return page;
	}

	/**
	 * 验证登录名是否存在
	 * @param email		email
	 * @return
	 */
	@Override
	public int selectUserByEmail(String email) {
		List<BfUser> list = this.userDao.selectUserByEmail(email);
		return list.size();
	}
	
	/**
	 * 查询国家列表
	 * @return
	 */
	@Override
    public @ResponseBody List<BfCountry> selectCountry() {
		List<BfCountry> list = this.userDao.selectCountry();
		return list;
	}

	/**
	 * 增加用户
	 * @param user	用户信息
	 * @return
	 */
	@Override
	public Integer addUser(BfUser user) {
		return this.userDao.addUser(user);
	}

	/**
	 * 修改用户
	 * @param user	用户信息
	 * @return
	 */
	@Override
	public void updateUser(BfUser user) {
		this.userDao.updateUser(user);
	}

	/**
	 * 查询用户详情
	 * @param userId	用户Id
	 * @return
	 */
	@Override
	public BfUser selectUserDetail(int userId) {
		return this.userDao.selectUserDetail(userId);
	}

	/**
	 * 删除用户
	 * @param userId	用户Id
	 * @return
	 */
	@Override
	public void deleteUser(int userId) {
		BfUser user = this.userDao.selectUserDetail(userId);
		this.userDao.deleteUser(user);
	}
}
